<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center oneclickOrdering_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub oneclickOrdering_fd0_0'>
          <view class='flex flex-wrap align-center oneclickOrdering_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  oneclickOrdering_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='oneclickOrdering_fd0_0_c1_c0'>一键下单</text>
          </view>
          <view class='flex flex-wrap align-center justify-end oneclickOrdering_fd0_0_c0'>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <benben-popup v-model="popupShow1697529646535" :mask="true" :mask-close-able="true" mode='center' :z-index='999'>
        <!---帮砍flex布局开始-->
        <view class="flex benben-flex-layout flex-wrap align-center">
          <view class='flex flex-direction flex-wrap align-stretch oneclickOrdering_fd1_0'>
            <view class='flex flex-direction flex-wrap align-center'>
              <text class='oneclickOrdering_fd1_0_c0_c0'>免责协议</text>
            </view>
            <view class="contentbox">
              <jyf-parser class='oneclickOrdering_fd1_0_c1' :html="content | richTextFormat">
              </jyf-parser>
            </view>

            <view class='flex flex-wrap align-center justify-center'>
              <button class='oneclickOrdering_fd1_0_c2_c0' @tap.stop="popupShow1697529646535=false">同意</button>
            </view>
            <view class='flex flex-wrap align-start justify-end oneclickOrdering_fd1_0_c3'
              @tap.stop="popupShow1697529646535=false">
              <image class='oneclickOrdering_fd1_0_c3_c0' mode="aspectFit" :src='STATIC_URL+"45.png"'></image>
            </view>
          </view>
        </view>

        <!---帮砍flex布局结束-->

      </benben-popup>
      <benben-popup v-model="popupShow1697607738993" :mask="true" :mask-close-able="true" mode='center' :z-index='999'>
        <!---flex布局flex布局开始-->
        <view class="flex flex-direction align-center benben-flex-layout oneclickOrdering_flex_2">
          <text class='oneclickOrdering_fd2_0'>您的积分不足，请联系管理员
            充值或者捐赠农具获得积分</text>
          <view class='flex flex-wrap align-center'>
            <button class='oneclickOrdering_fd2_1_c0' @tap.stop="handleJumpDiy"
          data-type="redirectTo" :data-url="`/pages/my/aboutUs/aboutUs`">确定</button>
          </view>
        </view>

        <!---flex布局flex布局结束-->

      </benben-popup>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout oneclickOrdering_flex_3">
        <view class='flex flex-wrap align-center justify-center oneclickOrdering_fd3_0' @tap.stop="handleJumpDiy"
          data-type="navigateTo" :data-url="`/pages/my/harvestAddress/harvestAddress?type=1`" v-if="!address_id">
          <image class='oneclickOrdering_fd3_0_c0' mode="aspectFill" :src='STATIC_URL+"40.png"'></image>
          <text class='oneclickOrdering_fd3_0_c1'>点击添加地址</text>
        </view>
        <view class='oneclickOrdering_fd3_0' @tap.stop="handleJumpDiy" data-type="navigateTo"
          :data-url="`/pages/my/harvestAddress/harvestAddress?type=1`" v-else>
          <view class="flex align-center">
            <view class="oneclickOrdering_fd3_0_c1">{{address.name}} </view>
            <view class="oneclickOrdering_fd3_0_c1 margin-left-sm">{{address.mobile}} </view>
          </view>

          <view class='oneclickOrdering_fd3_0_c1'>{{address.address_detail}}</view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch oneclickOrdering_fd3_1'
          @tap.stop="pickerDiy1697528599139=true">
          <text class='oneclickOrdering_fd3_1_c0'>借农具时长（天）</text>
          <view class='flex flex-wrap align-center'>
            <input class='oneclickOrdering_fd3_1_c1_c0' :disabled="true" type="text" :placeholder="`请选择租农具时长`" confirm-type="done"
              :maxlength="-1" placeholder-style="color:#999;font-size:28rpx" v-model="time_label" />
            <image class='oneclickOrdering_fd3_1_c1_c1' mode="aspectFit" :src='STATIC_URL+"41.png"'></image>
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch oneclickOrdering_fd3_2'>
          <view class='flex flex-wrap align-center'>
            <text class='oneclickOrdering_fd3_2_c0_c0'>借农具</text>
            <text class='oneclickOrdering_fd3_2_c0_c1'>共</text>
            <text class='oneclickOrdering_fd3_2_c0_c1'>{{goodsList.length}}</text>
            <text class='oneclickOrdering_fd3_2_c0_c1'>件</text>
          </view>
          <view class='flex flex-wrap align-center oneclickOrdering_fd3_2_c1' v-for="(item,index) in goodsList"
            :key="index">
            <image class='oneclickOrdering_fd3_2_c1_c0' mode="aspectFill" :src='item.thumb'></image>
            <view class='flex flex-direction flex-wrap align-stretch flex-sub'>
              <text class='oneclickOrdering_fd3_2_c1_c1_c0'>{{item.name}}</text>
              <view class='flex flex-wrap align-center oneclickOrdering_fd3_2_c1_c1_c1'>
                <text class='oneclickOrdering_fd3_2_c1_c1_c1_c0' v-for="(itemC,indexC) in item.category_name"
                  v-if="item.category_name.length&& indexC<2">{{itemC}}</text>
                <!-- <text class='oneclickOrdering_fd3_2_c0_c1'>二级分类</text> -->
              </view>
              <view class='flex flex-wrap align-center'>
                <text class='oneclickOrdering_fd3_2_c1_c1_c2_c0'>{{item.shop_price}}</text>
                <text class='oneclickOrdering_fd3_2_c1_c1_c2_c1'>积分</text>
                <text class='oneclickOrdering_fd3_2_c1_c1_c2_c2'>{{item.number}}</text>
              </view>
            </view>
          </view>
        </view>
      </view>

      <!---flex布局flex布局结束-->
      <benben-popup v-model="popupShow1697608070956" :mask="true" :mask-close-able="true" mode='center' :z-index='999'>
        <!---flex布局flex布局开始-->
        <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout">
          <view class='flex flex-direction flex-wrap align-center oneclickOrdering_fd4_0'>
            <text class='oneclickOrdering_fd4_0_c0'>请开通会员后租借农具</text>
            <text class='oneclickOrdering_fd4_0_c1' @tap.stop="handleJumpDiy" data-type="redirectTo"
              :data-url="`/pages/my/activateMembership/activateMembership`">成为会员</text>
          </view>
        </view>

        <!---flex布局flex布局结束-->

      </benben-popup>
      <!--选择器-借农具时长开始 -->
      <benben-picker ref="benbenWritePickerCodepicker5" :visible.sync="pickerDiy1697528599139" :label.sync='time_label'
        :value.sync='time_value' :options='time' mode='selector' :mask-show='true' :timeout='true' :picker-height='88'
        default-type='aid' :default-props='{"label":"day","value":"aid"}'>
        <template #picker-header>
          <view class='flex flex-wrap align-center justify-between oneclickOrdering_picker5_0'>
            <text class='oneclickOrdering_picker5_0_c0' @tap="$refs.benbenWritePickerCodepicker5.cancel()">取消</text>
            <text class='oneclickOrdering_picker5_0_c1'>借农具时长</text>
            <text class='oneclickOrdering_picker5_0_c2'
              @tap="$refs.benbenWritePickerCodepicker5.pickerConfirm()">确定</text>
          </view>
        </template>
      </benben-picker>
      <!--选择器-借农具时长结束 -->
      <view class="flex flex-direction flex-wrap align-stretch flex oneclickOrdering_flex_6">
        <view class='flex flex-wrap align-center justify-center' @tap.stop="consentAgreeFunc()">
          <benben-flex-switch-new class-name='flex flex oneclickOrdering_fd6_0_c0' v-model="agreement" :disabled='false'
            :auto='true'>
            <template v-slot:checked>

              <view class='flex flex position-relative align-center'>
                <image class='oneclickOrdering_checkfd6_0_c0_c0_c0' mode="aspectFit" :src='STATIC_URL+"44.png"'></image>
              </view>

            </template>
            <template v-slot:unchecked>

              <view class='flex flex position-relative justify-end align-center'>
                <image class='oneclickOrdering_noCheckfd6_0_c0_c1_c0' mode="aspectFit" :src='STATIC_URL+"43.png"'>
                </image>
              </view>

            </template>
          </benben-flex-switch-new>
          <text class='oneclickOrdering_fd6_0_c1' @tap.stop="popupShow1697529646535=true">免责协议</text>
        </view>
        <view class='flex flex-wrap align-center oneclickOrdering_fd6_1'>
          <view class='flex flex-wrap align-center'>
            <text class='oneclickOrdering_fd6_1_c0_c0'>应付合计</text>
            <text class='oneclickOrdering_fd6_1_c0_c1'>{{goodsInfo.payable_money}}</text>
            <text class='oneclickOrdering_fd6_1_c0_c2'>积分</text>
          </view>
          <button class='oneclickOrdering_fd6_1_c1' @tap.stop="placeOrderFunc()">提交</button>
        </view>

      </view>
      <view :style="{height: '179rpx'}"></view>


    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  export default {
    components: {},


    data() {
      return {
        "pickerDiy1697528599139": false,
        "popupShow1697608070956": false,
        "popupShow1697607738993": false,
        "popupShow1697529646535": false,
        "time": [],
        "time_value": "",
        "time_label": "",
        "agreement": false,
        "goodsList": '',
        "placeOrder": {
          "order_sn": "",
          "payable_money": "",
          "pay_status": "",
          "timeout": "",
          "is_zero": ""
        },
        "goods": "1",
        "num": "",
        ids: '',
        goodsInfo: "",
        address: '',
        address_id: '',
        content: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      let {
        goods,
        num,
        id
      } = options
      if (goods !== undefined) this.goods = goods
      if (num !== undefined) this.num = num
      if (id !== undefined) this.ids = id
      this.getGoodsFunc()
      this.getRule()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {
      uni.$on('address', data => {
        console.log('address', data)
        this.address = data
        this.address_id = data.address_id
      })

    },
    onHide() {
      this.popupShow1697607738993=false
    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      getRule() {
        this.$api.post(global.apiUrls.post6527a4d87f7f0, {}).then(res => {
          this.time = res.data.data
        })
        this.$api.post(global.apiUrls.post62c393b950315, {
          aid: '15',
        }).then(res => {
          this.content = res.data.data.content
        })
      },
      //同意协议
      consentAgreeFunc() {
        // this.agreement=!this.agreement
        // if (this.agreement === true) {
        //   return
        // } else if (this.agreement === false) {
        //   this.popupShow1697529646535 = true;
        // }
      },
      //获取商品
      async getGoodsFunc() {
        //请求方法
        //数据验证

        let datagoodsList = await this.$api.post(global.apiUrls.post62ba581c43bf9, {
          cart_ids: this.ids
        });

        if (datagoodsList.data.code == 0) {
          this.$message.info(datagoodsList.data.msg);
          return
        }
        if (datagoodsList.data.code == '-111') {
          this.popupShow1697608070956 = true
          // this.$message.info(datagoodsList.data.msg);
          // setTimeout(res => {
          //   uni.redirectTo({
          //     url: `/pages/my/activateMembership/activateMembership`
          //   })
          // }, 800)

          return
        }
        let infogoodsList = datagoodsList.data;
        this.goodsInfo = infogoodsList.data
        this.address = this.goodsInfo.address
        this.address_id = this.address.address_id
        this.goodsList = this.goodsInfo.goods
        console.log('oooo', this.address)
        // this.goodsList = infogoodsList.data.goods
      },
      //下单商品
      async placeOrderFunc() {

        if (!validate(this.time_value, 'require')) {
          this.$message.info('请选择天数');
          return false;
        }
        if (this.agreement === false) {
          this.$message.info('请勾选免责协议');
          return false;
        }
        //请求方法
        //数据验证
        let order_goods = this.goodsList.map(item => {
          const obj = {
            goods_id: item.goods_id,
            num: item.number,
            sku_id: ''
          }
          return obj
        })

        let dataplaceOrder = await this.$api.post(global.apiUrls.post62c803a711123, {
          address_id: this.address_id,
          order_goods: JSON.stringify(order_goods),
          payable_money: this.goodsInfo.payable_money,
          order_type: '3',
          lease_days: this.time_label
        });

        if (dataplaceOrder.data.code != 1) {
          this.$message.info(dataplaceOrder.data.msg);
          setTimeout(re => {
            uni.navigateBack()
          }, 800)

          return
        }
        let infoplaceOrder = dataplaceOrder.data;
        this.placeOrder = infoplaceOrder.data
        this.goPay()
      },
      goPay() {
        this.$api.post(global.apiUrls.post6368d2de26ca9, {
          order_sn: this.placeOrder.order_sn,
          pay_password: '123456'
        }).then(res => {
          if (res.data.code == 1) {
            this.$urouter.navigateTo(`/pages/agriculturalToolrack/successfullyBooked/successfullyBooked`);
          } else if (res.data.code == '-1') {
            this.popupShow1697607738993 = true
          } else {
            this.$message.info(res.data.msg);
          }
        })
      }
    }
  };
</script>
<style lang="scss" scoped>
  .contentbox {
    height: 550rpx;
    overflow-y: scroll;
  }

  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: var(--benbenbgColor0);
    background-size: 100% auto;
  }

  .oneclickOrdering_flex_0 {
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
  }

  .oneclickOrdering_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 500;
    color: #333;
    line-height: 88rpx;
  }

  .oneclickOrdering_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .oneclickOrdering_fd0_0_c0 {
    width: 120rpx;
  }

  .oneclickOrdering_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .oneclickOrdering_fd1_0_c3_c0 {
    width: 40rpx;
    height: 40rpx;
  }

  .oneclickOrdering_fd1_0_c3 {
    width: 40rpx;
    height: 40rpx;
    position: absolute;
    top: 20rpx;
    right: 24rpx;
  }

  .oneclickOrdering_fd1_0_c2_c0 {
    background: #E63838;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    font-size: 32rpx;
    color: #fff;
    width: 176rpx;
    height: 72rpx;
    line-height: 80rpx;
    font-weight: 500;
  }

  ::v-deep .oneclickOrdering_fd1_0_c1 {
    width: 100%;
    margin: 24rpx 0rpx 32rpx 0rpx;
  }

  .oneclickOrdering_fd1_0_c0_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
  }

  .oneclickOrdering_fd1_0 {
    background: #FFFFFF;
    border-radius: 20rpx 20rpx 20rpx 20rpx;
    width: 590rpx;
    padding: 48rpx 44rpx 40rpx 44rpx;
    position: relative;
  }

  .oneclickOrdering_flex_2 {
    background: rgba(255, 255, 255, 1);
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 48rpx 52rpx 40rpx 52rpx;
  }

  .oneclickOrdering_fd2_1_c0 {
    background: #E63838;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    font-size: 28rpx;
    color: var(--benbenFontColor3);
    padding: 0rpx 61rpx 0rpx 61rpx;
    margin: 0rpx 0rpx 0rpx 12rpx;
    width: 176rpx;
    height: 72rpx;
  }

  .oneclickOrdering_fd2_0 {
    font-size: 32rpx;
    font-weight: 500;
    color: #333333;
    margin: 0rpx 0rpx 40rpx 0rpx;
  }

  .oneclickOrdering_flex_3 {
    margin: 36rpx 24rpx 0rpx 24rpx;
  }

  .oneclickOrdering_fd3_2_c1_c1_c2_c2 {
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
    margin: 0rpx 0rpx 0rpx auto;
  }

  .oneclickOrdering_fd3_2_c1_c1_c2_c1 {
    color: rgba(230, 56, 56, 1);
    font-size: 24rpx;
    font-weight: 700;
  }

  .oneclickOrdering_fd3_2_c1_c1_c2_c0 {
    color: rgba(230, 56, 56, 1);
    font-size: 36rpx;
    font-weight: 700;
  }

  .oneclickOrdering_fd3_2_c1_c1_c1_c0 {
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
    margin: 0rpx 16rpx 0rpx 0rpx;
  }

  .oneclickOrdering_fd3_2_c1_c1_c1 {
    margin: 0rpx 0rpx 55rpx 0rpx;
  }

  .oneclickOrdering_fd3_2_c1_c1_c0 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 500;
    margin: 0rpx 0rpx 24rpx 0rpx;
  }

  .oneclickOrdering_fd3_2_c1_c0 {
    width: 200rpx;
    height: 200rpx;
    margin: 0rpx 24rpx 0rpx 0rpx;
    border-radius: 16rpx;
  }

  .oneclickOrdering_fd3_2_c1 {
    background: #FFFFFF;
    margin: 24rpx 0rpx 0rpx 0rpx;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 32rpx 24rpx 32rpx 24rpx;
  }

  .oneclickOrdering_fd3_2_c0_c1 {
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
  }

  .oneclickOrdering_fd3_2_c0_c0 {
    color: #333333;
    font-size: 24rpx;
    font-weight: 500;
    margin: 0rpx 12rpx 0rpx 0rpx;
  }

  .oneclickOrdering_fd3_2 {
    background: #FFFFFF;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 32rpx 24rpx 32rpx 24rpx;
  }

  .oneclickOrdering_fd3_1_c1_c1 {
    width: 40rpx;
    height: 40rpx;
    margin: 0rpx 0rpx 0rpx auto;
  }

  .oneclickOrdering_fd3_1_c1_c0 {
    color: #333;
    font-size: 28rpx;
    font-weight: 400;
  }

  .oneclickOrdering_fd3_1_c0 {
    color: #333333;
    font-size: 24rpx;
    font-weight: 500;
    margin: 0rpx 0rpx 16rpx 0rpx;
  }

  .oneclickOrdering_fd3_1 {
    background: #FFFFFF;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 32rpx 24rpx 32rpx 24rpx;
    margin: 0rpx 0rpx 24rpx 0rpx;
  }

  .oneclickOrdering_fd3_0_c1 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 500;
  }

  .oneclickOrdering_fd3_0_c0 {
    width: 60rpx;
    height: 60rpx;
    margin: 0rpx 24rpx 0rpx 0rpx;
  }

  .oneclickOrdering_fd3_0 {
    background: #FFFFFF;
    border-radius: 16rpx 16rpx 16rpx 16rpx;
    padding: 30rpx 20rpx 30rpx 20rpx;
    margin: 0rpx 0rpx 24rpx 0rpx;
  }

  .oneclickOrdering_fd4_0_c1 {
    color: #EACEB8;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 44rpx;
    position: absolute;
    bottom: 63rpx;
    left: 246rpx;
  }

  .oneclickOrdering_fd4_0_c0 {
    color: #EACEB8;
    font-size: 32rpx;
    font-weight: 500;
    position: absolute;
    top: 48rpx;
    left: 158rpx;
  }

  .oneclickOrdering_fd4_0 {
    background: url(https://api.nongjugongxiang.com/nongju/images/73.png) no-repeat;
    background-size: 100% auto;
    width: 599rpx;
    height: 328rpx;
    position: relative;
  }

  .oneclickOrdering_picker5_0_c2 {
    color: #E63838;
    font-size: 32rpx;
    font-weight: 500;
  }

  .oneclickOrdering_picker5_0_c1 {
    color: #333333;
    font-size: 36rpx;
    font-weight: 500;
  }

  .oneclickOrdering_picker5_0_c0 {
    color: #BFBFBF;
    font-size: 32rpx;
    font-weight: 400;
  }

  .oneclickOrdering_picker5_0 {
    border-bottom: 1px solid #eee;
    background: #fff;
    padding: 0rpx 32rpx 0rpx 32rpx;
    line-height: 88rpx;
    border-radius: 25rpx 25rpx 0rpx 0rpx;
    background-size: 100% auto !important;
  }

  .oneclickOrdering_flex_6 {
    width: 750rpx;
    height: 179rpx;
    overflow: hidden;
    z-index: 10;
    position: fixed;
    bottom: 0rpx;
    left: 0;
    background-color: #f8f8f8;
  }

  .oneclickOrdering_fd6_1_c1 {
    background: #E63838;
    border-radius: 40rpx 40rpx 40rpx 40rpx;
    width: 258rpx;
    line-height: 80rpx;
    font-size: 32rpx;
    color: #fff;
    height: 80rpx;
    margin: 0rpx 24rpx 0rpx auto;
  }

  .oneclickOrdering_fd6_1_c0_c2 {
    color: rgba(230, 56, 56, 1);
    font-size: 24rpx;
    font-weight: 700;
  }

  .oneclickOrdering_fd6_1_c0_c1 {
    color: rgba(230, 56, 56, 1);
    font-size: 36rpx;
    font-weight: 700;
  }

  .oneclickOrdering_fd6_1_c0_c0 {
    margin: 0rpx 16rpx 0rpx 24rpx;
    color: #999999;
    font-size: 24rpx;
    font-weight: 400;
  }

  .oneclickOrdering_fd6_1 {
    background: rgba(255, 255, 255, 1);
    margin: 24rpx 0rpx 0rpx 0rpx;
    background-size: 100% auto;
    padding: 10rpx 0rpx 10rpx 0rpx;
  }

  .oneclickOrdering_fd6_0_c1 {
    color: #E63838;
    font-size: 24rpx;
    font-weight: 400;
  }

  .oneclickOrdering_noCheckfd6_0_c0_c1_c0 {
    border-radius: 24rpx 24rpx 24rpx 24rpx;
    width: 32rpx;
    height: 32rpx;
  }

  .oneclickOrdering_checkfd6_0_c0_c0_c0 {
    width: 32rpx;
    height: 32rpx;
    border-radius: 24rpx 24rpx 24rpx 24rpx;
  }

  ::v-deep .oneclickOrdering_fd6_0_c0 {
    margin: 0rpx 13rpx 0rpx 0rpx;
  }
</style>
